package com.tanhua.admin.controller;

import com.tanhua.admin.service.DashboardService;
import com.tanhua.model.vo.SummaryVo;
import com.tanhua.model.vo.UserComparable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping("/dashboard")
public class DashboardController {
    @Autowired
    private DashboardService dashboardService;
    @GetMapping("/summary")
    public ResponseEntity summary() throws ParseException {
        SummaryVo vo = dashboardService.summary();
        return ResponseEntity.ok(vo);
    }
    @GetMapping("/users")
   public ResponseEntity user(Long sd, Long ed, String type){
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date(sd);
        String sd1 = dateFormat.format(date);
        Date date1 = new Date(ed);
        String ed1 = dateFormat.format(date1);
        UserComparable userComparable = dashboardService.user(sd1, ed1, type);
       return ResponseEntity.ok(userComparable);
   }

}
